﻿// ***********************************************************************
// Assembly         : NIMServerApi
// Author           : Walter
// Created          : 11-15-2016
//
// Last Modified By : Walter
// Last Modified On : 11-15-2016
// ***********************************************************************
// <copyright file="BaseMethod.cs" company="51iface">
//     Copyright 51iface©  2016
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;

namespace NIMServerApi.Methods
{
    /// <summary>
    /// Class BaseMethod.
    /// </summary>
    public class BaseMethod
    {
        protected string appKey;
        protected string appSecret;

        public BaseMethod(string appKey, string appSecret)
        {
            this.appKey = appKey;
            this.appSecret = appSecret;
        }


        /// <summary>
        /// Tries the get json value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json">The json.</param>
        /// <param name="key">The key.</param>
        /// <returns>T.</returns>
        protected T TryGetJsonValue<T>(string json,string key)
        {
            if (!string.IsNullOrEmpty(json))
            {
                try
                {
                    var t = Newtonsoft.Json.Linq.JObject.Parse(json);
                    return t.Value<T>(key);
                }
                catch (Exception ex)
                {
                    //log
                    return default(T);
                }
            }

            return default(T);
        }
    }
}